package demo7;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Person {
    private String name;

    public Person() {
        System.out.println("1.Person的构造器被调用了。");
    }

    public String getName() {
        return name;
    }

    @Value("长得帅")
    public void setName(String name) {
        this.name = name;
        System.out.println("2.name的set方法被调用了，初始化了name属性。");
    }

    public void play(){
        System.out.println(name+"出去玩。");
    }

    @PostConstruct
    public void init(){
        System.out.println("3.Spring容器将Person对象初始化完毕，name"+name);
    }

    @PreDestroy
    public void preDestory(){
        System.out.println("5.容器要关闭了，通知当前对象。");
    }
}
